-
Notifications
You must be signed in to change notification settings - Fork 168
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Provide Custom Info as Pillar data #3093
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the efforts here, I am being a bit nitpicky but I think we are already on a good path!
Just not to forget, once the code is done please also open an issue or PR to our docs, this is a small but nice piece of news to share for the scripters out there.
Thanks, it's been a long time since I hoped this will one day be done!
@@ -2075,6 +2076,10 @@ public int setCustomValues(User loggedInUser, Integer sid, Map<String, String> v | |||
} | |||
} | |||
|
|||
server.asMinionServer().ifPresent(minion -> { | |||
MinionPillarManager.INSTANCE.generatePillar(minion); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know it's a bit more work, but I'd encourage creating an ad-hoc MinionPillarGenerator
for this use case, or any change to custom info will entail the full regeneration of all pillar data, which can take a bit of time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean adding new pillar file or calling only MinionGeneralPillarGenerator?
Anyway, if I understand correctly, the write should go via MinionPillarManager.INSTANCE, right?
Is it OK to change MinionPillarManager to use named variables instead of list to hold MinionPillarFileManager instances and add MinionPillarManager.generatePillar with arguments to use only selected MinionPillarFileManager ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean adding new pillar file or calling only MinionGeneralPillarGenerator?
I meant adding a new pillar file and related Generator class. Actually I made a copypaste mistake in that comment - meaning MinionPillarGenerator
but actually writing MinionGeneralPillarGenerator
, sorry for having confused you.
Anyway, if I understand correctly, the write should go via MinionPillarManager.INSTANCE, right?
Only if you want to regenerate all pillar data, which IIUC should not be the case here.
Is it OK to change MinionPillarManager to use named variables instead of list to hold MinionPillarFileManager instances and add MinionPillarManager.generatePillar with arguments to use only selected MinionPillarFileManager ?
It's not a bad idea FMPOV, the only thing I see is that, so far, the pattern has been to just instantiate a new MinionPillarFileManager(new MySpecificPillarGenerator())
and call updatePillarFile()
.
So I would welcome such change, at the condition it comes in its own separate commit (or even PR if you so prefer) and that all similar cases are changed in one shot (I see three of them apart from tests, see callers of MinionPillarGenerator.generatePillarData()
as displayed by IntelliJ's Navigate -> Call Hierarchy
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, I am working on it.
For completeness, ad-hoc MinionPillarFileManager instances do not work with unit tests which change pillar root.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One more reason to go ahead with such a refactoring!
@@ -134,6 +135,9 @@ public ActionForward execute(ActionMapping mapping, | |||
cdv.setCreator(user); | |||
cdv.setLastModifier(user); | |||
request.setAttribute(VAL_PARAM, form.get(VAL_PARAM)); | |||
server.asMinionServer().ifPresent(minion -> { | |||
MinionPillarManager.INSTANCE.generatePillar(minion); | |||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am a bit confused by the logic from lines above this. It seems to me that addCustomDataValue
already creates a new CustomDataValue
instance and sets it if null, and now we have the logic repeated here.
I would not mind in the context of this PR normally, but here we are adding code which is clearly back-end (pillar generation) to a front-end class (an Action), and was wondering where it would be placed best.
Would it be possible to fold the code above and the pillar generation inside of addCustomDataValue
- either to be left in Server
or moved into ServerFactory
?
0e88c8e
to
5557d9e
Compare
* @param minion the minion server | ||
* @param subsets subsets of pillar, that should be generated | ||
*/ | ||
public void generatePillar(MinionServer minion, EnumSet<PillarSubset> subsets) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the EnumSet
is not really needed and makes it less convenient to use. Usually EnumSet
is a good way to represent flags in a typesafe way while still retaining the performance of bitfields but in this case we are just giving a list of things we want to iterate over and do something for each of them. Instead if would just do PillarSubset...
(varargs) so you can just pass multiple PillarSubset
as arguments without any additional wrapping. The method would then be just iterating over it with a switch.
* @param subsets subsets of pillar, that should be generated | ||
*/ | ||
public void generatePillar(MinionServer minion, EnumSet<PillarSubset> subsets) { | ||
if (subsets.contains(PillarSubset.ACCESS_TOKENS)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACCESS_TOKENS
does not seem to fit in with the rest as it does not generate pillar data but updates data for GENERAL
. I think it would be more consistent adding boolean refreshAccessTokens
as an extra parameter like its the case in the other method already.
|
||
if (updatePillar) { | ||
this.asMinionServer().ifPresent(minion -> { | ||
MinionPillarManager.INSTANCE.generatePillar(minion, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In my recent refactoring i started to reduce the usage of global static instances and tried to give a clearer picture of dependencies of different aspects of the codebase. Having the server (data class) directly generate its pillar data breaks that in a big way. I would suggest moving this code at least to the call site.
c5c9005
to
c92f280
Compare
Updated as requested. |
Ad-hoc MinionPillarFileManager instances do not work with unit tests, which change pillar root globally. With this change all pilar writes can go via MinionPillarManager.INSTANCE but it is still possible to generate only particular pillar file, if needed. Adjusted unit tests.
What does this PR change?
Provide Custom Info as Pillar data
GUI diff
No difference.
Documentation
Test coverage
Unit tests were added
DONE
Links
Fixes https://github.com/SUSE/spacewalk/issues/12016
Changelogs
If you don't need a changelog check, please mark this checkbox:
If you uncheck the checkbox after the PR is created, you will need to re-run
changelog_test
(see below)Re-run a test
If you need to re-run a test, please mark the related checkbox, it will be unchecked automatically once it has re-run: